package com.timoon.sample.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.timoon.sample.dao.InfoSortDAO;
import com.timoon.sample.dao.PassageDAO;
import com.timoon.sample.dao.model.InfoSort;
import com.timoon.sample.dao.model.InfoSortExample;
import com.timoon.sample.dao.model.Passage;
import com.timoon.sample.dao.model.PassageExample;
import com.timoon.sample.utils.SystemConfig;
import com.timoon.webcomponent.utility.info.Info1Service;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */

@Service(value="com.timoon.sample.service.InfoServiceImpl")
public class InfoServiceImpl implements Info1Service {
	
	@Resource
	private InfoSortDAO infoSortDAOImpl;
	
	@Resource
	private PassageDAO passageDAOImpl;

	@SuppressWarnings("unchecked")
	@Override
	public InfoSort getInfoByCode(final String code) {
		// TODO Auto-generated method stub
		
		List<InfoSort> infoSorts=this.infoSortDAOImpl.selectByExample(new InfoSortExample(){{
			this.createCriteria().andCodeEqualTo(code);
		}});
		
		if(infoSorts!=null&&infoSorts.size()==1){
			
		}else{
			String error="根据code查找[info_sort]出错,code="+code+"/查询结果:";
			String size=(infoSorts==null?"0":String.valueOf(infoSorts.size()));
			throw new RuntimeException(error+size);
		}
		return infoSorts.get(0);
	}

	@Override
	public List<Passage> getInfo() {
		// TODO Auto-generated method stub
		List<Passage> passages=this.passageDAOImpl.selectByExampleWithBLOBs(new PassageExample(){{
			this.createCriteria().andStatusNotEqualTo(SystemConfig.STATUS_DELETED).andTypeEqualTo(SystemConfig.PASSAGE_TYPE_KUAIBAO);
		}});
		
		if(passages.size()!=8){
			throw new RuntimeException("【快报资讯】取得passage期望个数：8/实际个数"+passages.size());
		}
		
		return passages;
	}

}
